﻿using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace NlogTest
{
    public static class LogHelper
    {
        /// <summary>
        /// 设置线程会话活动Id
        /// </summary>
        public static void SetActivityId(string activityId = null)
        {
            Trace.CorrelationManager.ActivityId = string.IsNullOrEmpty(activityId) ? Guid.NewGuid() : new Guid(activityId);
        }

        private static NLog.Logger _loger = null;
        private static NLog.Logger GetCurProLoger(string moduleName)
        {
            SetActivityId();
            return _loger = NLog.LogManager.GetLogger(moduleName);
        }
        /// <summary>
        /// 信息日志
        /// </summary>
        /// <param name="message"></param>
        public static void Info(string moduleName,string message)
        {
            _loger = GetCurProLoger(moduleName);
            _loger.Info(message);
        }
        /// <summary>
        /// 错误日志
        /// </summary>
        /// <param name="message"></param>
        public static void Error(string moduleName, string message)
        {
            _loger = GetCurProLoger(moduleName);
            _loger.Error(message);
        }
        /// <summary>
        /// 致命日志
        /// </summary>
        /// <param name="message"></param>
        public static void Fatal(string moduleName, string message)
        {
            _loger = GetCurProLoger(moduleName);
            _loger.Fatal(message);
        }

    }
}
